// numbers = [2,3,4], target = 6  不可以使用相同的元素

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (nums, target) {
  let len = nums.length
  let left = 0
  let right = len - 1
  while (left < right) {
    let sum = nums[left] + nums[right]
    if (sum === target) {
      return [left + 1, right + 1]
    } else if (sum > target) {
      right--
    } else {
      left++
    }
  }
};

console.log(twoSum([2, 3, 4], 6));